package com.example.activiti7.controller;

import com.example.activiti7.domain.model.req.DeployReq;
import com.example.activiti7.domain.model.req.QueryProcessDefinitionListReq;
import com.example.activiti7.domain.model.resp.Page;
import com.example.activiti7.domain.model.resp.Response;
import com.example.activiti7.domain.model.vo.ProcessDefinitionVO;
import com.example.activiti7.domain.service.ProcessDefinitionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/overflow/definition")
@Tag(name = "流程定义服务能力", description = "流程定义接口服务管理")
public class ProcessDefinitionController {
    private final ProcessDefinitionService processDefinitionService;

    public ProcessDefinitionController(ProcessDefinitionService processDefinitionService) {
        this.processDefinitionService = processDefinitionService;
    }

    @PostMapping(value = {"/deploy"})
    @Operation(summary = "流程部署发布")
    public Response<Boolean> deploy(@RequestBody DeployReq deployReq) throws Exception {
        return processDefinitionService.deploy(deployReq);
    }

    @DeleteMapping(value = {"/deployId/{deployId}"})
    @Operation(summary = "根据发布ID删除流程定义信息")
    @Parameters({
            @Parameter(name = "deployId", description = "部署ID"),
            @Parameter(name = "cascade", description = "级联删除，如果存在流程实例数据，流程实例数据也会进行删除，默认不传值为false")
    })
    public Response<Boolean> deleteByDeployId(@PathVariable("deployId") String deployId, boolean cascade) {
        return processDefinitionService.deleteByDeployId(deployId, cascade);
    }

    @DeleteMapping(value = {"/modelId/{modelId}"})
    @Operation(summary = "根据模型ID删除流程定义信息")
    @Parameters({
            @Parameter(name = "modelId", description = "模型ID"),
            @Parameter(name = "cascade", description = "级联删除，如果存在流程实例数据，流程实例数据也会进行删除，默认不传值为false")
    })
    public Response<Boolean> deleteByModelId(@PathVariable("modelId") String modelId, boolean cascade) {
        return processDefinitionService.deleteByModelId(modelId, cascade);
    }

    @PostMapping(value = {"/list"})
    @Operation(summary = "查询流程定义信息列表")
    public Response<Page<ProcessDefinitionVO, QueryProcessDefinitionListReq>> queryProcessDefinitions(@RequestBody QueryProcessDefinitionListReq req) {
        return processDefinitionService.queryProcessDefinitions(req);
    }

}
